package com.ruoyi.web.controller.applet;

import com.ruoyi.applet.appletUser.domain.AppletUser;
import com.ruoyi.applet.appletUser.service.IAppletUserService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 小程序用户Controller
 * @author ruoyi
 * @date 2024-11-19
 */
@Controller
@RequestMapping("/applet/appletUser")
public class AppletUserController extends BaseController {
    
    private final String prefix = "applet/appletUser";
    
    @Resource
    private IAppletUserService appletUserService;
    
    @RequiresPermissions("applet:appletUser:view")
    @GetMapping()
    public String appletUser() {
        return prefix + "/appletUser";
    }
    
    /**
     * 查询小程序用户列表
     */
    @RequiresPermissions("applet:appletUser:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AppletUser appletUser) {
        startPage();
        List<AppletUser> list = appletUserService.selectAppletUserList(appletUser);
        return getDataTable(list);
    }
    
    /**
     * 导出小程序用户列表
     */
    @RequiresPermissions("applet:appletUser:export")
    @Log(title = "小程序用户", businessType = BusinessType.EXPORT)
    @ResponseBody
    public AjaxResult export(AppletUser appletUser) {
        List<AppletUser> list = appletUserService.selectAppletUserList(appletUser);
        ExcelUtil<AppletUser> util = new ExcelUtil<AppletUser>(AppletUser.class);
        return util.exportExcel(list, "小程序用户数据");
    }
    
    /**
     * 新增小程序用户
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }
    
    /**
     * 新增保存小程序用户
     */
    @RequiresPermissions("applet:appletUser:add")
    @Log(title = "小程序用户", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AppletUser appletUser) {
        return toAjax(appletUserService.insertAppletUser(appletUser));
    }
    
    /**
     * 修改小程序用户
     */
    @RequiresPermissions("applet:appletUser:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        AppletUser appletUser = appletUserService.selectAppletUserById(id);
        mmap.put("appletUser", appletUser);
        return prefix + "/edit";
    }
    
    /**
     * 修改保存小程序用户
     */
    @RequiresPermissions("applet:appletUser:edit")
    @Log(title = "小程序用户", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AppletUser appletUser) {
        return toAjax(appletUserService.updateAppletUser(appletUser));
    }
    
    /**
     * 删除小程序用户
     */
    @RequiresPermissions("applet:appletUser:remove")
    @Log(title = "小程序用户", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(appletUserService.deleteAppletUserByIds(ids));
    }
}
